@echo off
chcp 65001 >nul
title Enterprise Portal Website - Local Server

echo.
echo ========================================
echo   Enterprise Portal Website Launcher
echo ========================================
echo.

:: Check if Python is installed
python --version >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Python not detected, please install Python first
    echo.
    echo Please visit https://www.python.org/downloads/ to download and install Python
    echo.
    pause
    exit /b 1
)

:: Get current directory
set "CURRENT_DIR=%~dp0"
cd /d "%CURRENT_DIR%"

echo [INFO] Current directory: %CURRENT_DIR%
echo [INFO] Starting local server...
echo.

:: Find available port
set PORT=8000
:check_port
netstat -an | find ":%PORT%" >nul
if %errorlevel% equ 0 (
    set /a PORT+=1
    goto check_port
)

echo [INFO] Using port: %PORT%
echo [INFO] Server address: http://localhost:%PORT%
echo.

:: Launch browser
echo [INFO] Opening browser...
timeout /t 2 /nobreak >nul
start "" "http://localhost:%PORT%"

:: Start Python server
echo [INFO] Server is running...
echo [TIP] Press Ctrl+C to stop the server
echo.
echo ========================================
echo.

python -m http.server %PORT%

:: Cleanup after server stops
echo.
echo [INFO] Server stopped
pause